package com.bjtu.boatmq.broker.service.outer;

import com.bjtu.boatmq.common.protocol.Message;

import java.util.ArrayList;
import java.util.List;

/**
 * broker与store交互类
 * TODO:邓晓雯完善
 */
public class Broker2StoreService {
    /**
     * 存储一条消息
     * @param message 待发送的消息
     * @return ①存储成功，返回偏移量；②存储失败，返回-1
     */
    public static int storeMessage(Message message){
        int offset = 10;
        return offset;
    }

    /**
     * 获取消息列表
     * @param topicName
     * @param partitionId
     * @param consumeOffset
     * @return
     */
    public static List<Message> getMessageList(String topicName, int partitionId, long consumeOffset){
        List<Message> messageList = new ArrayList<Message>();
        //TODO：获取message流程
        return messageList;
    }

    /**
     * 存储消费偏移量
     */
    public static int storeConsumeOffset(String consumerId,
                                         String topic,
                                         int partition,
                                         int haveConsumeoffset){
        return haveConsumeoffset;
    }

    /**
     * 获取消费偏移量
     * @param consumerId
     * @param topic
     * @param partition
     * @return
     */
    public static int getConsumeOffset(String consumerId,
                                       String topic,
                                       int partition){
        int consuemrOffset = 0;
        return consuemrOffset;
    }

    /**
     * 获取分区存储的偏移量
     * @param topic
     * @param partition
     * @return
     */
    public static int getPartitionOffset(String topic,
                                          int partition){
        int storeOffset = 10;
        return storeOffset;
    }
}
